//
//  DetectorQRCodeViewController.swift
//  EyepetizerImitative
//
//  Created by 田伟 on 2017/5/5.
//  Copyright © 2017年 个人. All rights reserved.
//

import UIKit
import CoreImage

class DetectorQRCodeViewController: UIViewController {
    @IBOutlet weak var sourceImageView: UIImageView!
    @IBOutlet weak var showMessageLabel: UILabel!
    @IBAction func detectorQRCode() {
        
        // MARK:- 获取要识别的图片
        guard let image = sourceImageView.image else {
            return
        }
        
        let result = TWQRCodeTool.detectorQRCodeImage(image: image, isDrawQRCodeFrame: true)
   
        // 结果字符串
        let resultStr = result.resultStrs
        showMessageLabel.text = resultStr!.description
        // 弹窗显示结果
        let alertVC = UIAlertController(title: "识别结果", message: showMessageLabel.text, preferredStyle: .alert)
        // 添加关闭行为
        let action = UIAlertAction(title: "关闭", style: .default) { (UIAlertAction) in
            self.dismiss(animated: true, completion: nil)
        }
        alertVC.addAction(action)
        // 弹窗alert视图
        present(alertVC, animated: true, completion: nil)
        
        
        // 描绘好边框的图片
        sourceImageView.image = result.resultImage
    }
}
